#include <iostream>
#include <vector>
using namespace std;

// 已知
int n;
int x;
// 未知
int cnt = 1e9;
vector<int> mp(2222222, -1e9);
int main()
{
    cin >> n;    
    for (int i = 1; i <= n; ++i)
    {
        cin >> x;
        cnt = min(cnt, i - mp[x] + 1);
        mp[x] = i;
    }
    if (cnt >= 1e9) cout << -1;
    else cout << cnt;
    return 0;
}